﻿$(document).ready(function() {

	/*- logo -*/
	$('.logo').sliderkit({
		auto: true,
		autospeed: 2500,
		tabs: true,
		freeheight: true,
		circular: true,
		panelfx: "none"
	});
	/*- promo-slider -*/
	$(".promo-slider").owlCarousel({
		autoPlay: 5000,
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 1,
		itemsDesktop: false,
		itemsDesktopSmall: false,
		itemsTablet: false,
		itemsMobile: false
	});
	/*- promo-slider -*/
	$(".hardware-repair__description__slider").owlCarousel({
		autoPlay: false,
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 1,
		itemsDesktop: false,
		itemsDesktopSmall: false,
		itemsTablet: false,
		itemsMobile: false
	});
	/*- slider-models -*/
	$(".slider-models").owlCarousel({
		autoPlay: false,
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 6,
		itemsDesktop: [1024, 5],
		itemsDesktopSmall: [960, 4],
		itemsTablet: [760, 3],
		itemsMobile: [580, 2],
	});
	/*- tabs -*/
	var galleryBig = $(".tabs__content");
	galleryBig.owlCarousel({
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 1,
		itemsDesktop: false,
		itemsDesktopSmall: false,
		itemsTablet: false,
		itemsMobile: false,
		autoHeight: true,
		mouseDrag : false,
		touchDrag: false,
		afterMove: function() {
			var slider = gallerySmall.data('owlCarousel');
			slider.userItems.removeClass('active').eq(this.currentSlide).addClass('active');
			slider.goTo(this.currentSlide);
		}
	});
	var gallerySmall = $(".tabs__title");
	gallerySmall.owlCarousel({
		items: 5,
		itemsDesktop: [1280, 4],
		itemsDesktopSmall: [1024, 3],
		itemsTablet: [820, 2],
		itemsMobile: [580, 1],
		afterInit: function() {
			this.userItems.eq(0).addClass('active');
			this.userItems.find('a').on('click', galleryBigUpdate);
		}
	});
	function galleryBigUpdate() {
		var slider = galleryBig.data('owlCarousel');
		var current = $(this).parents('.owl-item').index();
		slider.goTo(current);
		return false;
	}

	$(".next").click(function() {
		gallerySmall.trigger('owl.next');
		galleryBig.trigger('owl.next');
	});
	$(".prev").click(function() {
		gallerySmall.trigger('owl.prev');
		galleryBig.trigger('owl.prev');
	});
	/*- global-form__tabs -*/
	$(".global-form__tabs").sliderkit({
		auto: false,
		tabs: true,
		freeheight: true,
		circular: true,
		panelfx: "none"
	});
	/*- social-network__tabs -*/
	$(".social-network__tabs").sliderkit({
		auto: false,
		tabs: true,
		freeheight: true,
		circular: true,
		panelfx: "none"
	});
	/*- main-navi__button -*/
	$('.main-navi__button').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		} else {
			$(this).parent().addClass('open');
		}
	});
	/*- hardware-repair__info -*/
	$('.hardware-repair__name__link').click(function(e) 
	{
//		$('li.hardware-repair__info__item').removeClass("open");
//		if ($(this).parents('.hardware-repair__info__item').hasClass('open')) {
//			$(this).parents('.hardware-repair__info__item').removeClass('open');
//		} else {
//			$(this).parents('.hardware-repair__info__item').addClass('open');
//		}
		if ($(this).parent('li').parent('ul').parent('.hardware-repair__info__item').is('.open')){
			$(this).parent('li').parent('ul').parent('.hardware-repair__info__item').removeClass('open');
		}else{
			$('li.hardware-repair__info__item').removeClass("open");
			$(this).parent('li').parent('ul').parent('.hardware-repair__info__item').addClass('open');
		}
	});
	/*- feedback-list__form -*/
//	$('.feedback-list__form__link').click(function(e) {
//		
//		if($(this).parent().hasClass('open')) {
//			$(this).parent().removeClass('open');
//		} else {
//			$(this).parent().addClass('open');
//		}
//	});	

	/*- hardware-repair__close -*/
	$('.hardware-repair__close').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		}
	});
	/*- header__top-panel__navi__section -*/
	$('.header__top-panel__navi__section').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		} else {
			$(this).parent().addClass('open');
		}
	});
	/*- rate -*/
	// $('.rate').raty({ score: 4 });

	/*- choice-courier -*/
	$('.choice-courier .checkbox label').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		} else {
			$(this).parent().addClass('open');
		}
	});
	/*- user-panel__button -*/
	$('.user-panel__button').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		} else {
			$(this).parent().addClass('open');
		}
	});
	/*- search-form__button -*/
	$('.search-form__button').click(function(e) {

		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
		} else {
			$(this).parent().addClass('open');
		}
	});
	/*- global-tabs -*/
	var tabsBig = $(".global-tabs__content");
	tabsBig.owlCarousel({
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 1,
		itemsDesktop: false,
		itemsDesktopSmall: false,
		itemsTablet: false,
		itemsMobile: false,
		autoHeight: true,
		afterMove: function() {
			var slider = tabsSmall.data('owlCarousel');
			slider.userItems.removeClass('active').eq(this.currentSlide).addClass('active');
			slider.goTo(this.currentSlide);
		}
	});
	var tabsSmall = $(".global-tabs__title");
	tabsSmall.owlCarousel({
		items: 3,
		itemsDesktop: [1380, 2],
		itemsDesktopSmall: [1023, 1],
		itemsTablet: [768, 2],
		itemsMobile: [680, 1],
		afterInit: function() {
			this.userItems.eq(0).addClass('active');
			this.userItems.find('a').on('click', tabsBigUpdate);
		}
	});
	function tabsBigUpdate() {
		var slider = tabsBig.data('owlCarousel');
		var current = $(this).parents('.owl-item').index();
		slider.goTo(current);
		return false;
	}

	$(".next").click(function()
	{
		tabsSmall.trigger('owl.next');
	});
	$(".prev").click(function()
	{
		tabsSmall.trigger('owl.prev');
	});
	/*- photo-gallery -*/
	var gallerBig = $(".photo-gallery__big");
	gallerBig.owlCarousel({
		navigation: true, // Show next and prev buttons
		slideSpeed: 300,
		paginationSpeed: 400,
		items: 1,
		itemsDesktop: false,
		itemsDesktopSmall: false,
		itemsTablet: false,
		itemsMobile: false,
		afterMove: function() {
			var slider = gallerSmall.data('owlCarousel');
			slider.userItems.removeClass('active').eq(this.currentSlide).addClass('active');
			slider.goTo(this.currentSlide);
		}
	});
	var gallerSmall = $(".photo-gallery__small");
	gallerSmall.owlCarousel({
		items: 4,
		itemsDesktop: [920, 3],
		itemsDesktopSmall: [768, 5],
		itemsTablet: [768, 4],
		itemsMobile: [460, 2],
		afterInit: function() {
			this.userItems.eq(0).addClass('active');
			this.userItems.find('a').on('click', gallerBigUpdate);
		}
	});
	function gallerBigUpdate()
	{
		var slider = gallerBig.data('owlCarousel');
		var current = $(this).parents('.owl-item').index();
		slider.goTo(current);
		return false;
	}

	$(".next").click(function()
	{
		gallerSmall.trigger('owl.next');
	});
	$(".prev").click(function()
	{
		gallerSmall.trigger('owl.prev');
	});
	$Player.init();
	mobi03 =
			{
				setUData: function(data, value)
				{
					if (typeof localStorage.mobi03 === 'undefined')
					{
						localStorage.mobi03 = "true";
					}
					if (typeof data === 'object')
					{
						$.each(data, function(index, row)
						{
							localStorage.setItem("mobi03." + index, (typeof (row) === 'object') ? JSON.stringify(row) : row);
						});
					}
					else if (typeof value !== 'undefined')
					{
						localStorage.setItem("mobi03." + data, value);
					}

				},
				getUData: function(data)
				{
					if (typeof localStorage.mobi03 === 'undefined')
					{
						return null;
					}
					if (typeof localStorage["mobi03." + data ] === 'undefined')
					{
						return null;
					}
					var _temp = false;
					try
					{
						_temp = JSON.parse(localStorage.getItem("mobi03." + data));
					}
					catch (Exception)
					{
						_temp = localStorage.getItem("mobi03." + data);
					}
					return _temp;
				},
				showMessage: function(title, description)
				{
					$('body').append('<a id="a_NOTIF_" style="display:none;" href="#_NOTIFICATION_" class="fancybox"></a><div class="your-city" id="_NOTIFICATION_"><h3 class="popup-title">' + title + '</h3><p style=" color: #53707E; font: italic 15px \'Georgia\',sans-serif;">' + description + '</p></div>');
					$('a#a_NOTIF_').trigger('click');
					$('a#a_NOTIF_').remove();
					return false;
				},
				cyr2lat: function(str, firsturl)
				{
					var cyr2latChars = new Array(
							['а', 'a'], ['б', 'b'], ['в', 'v'], ['г', 'g'], ['д', 'd'], ['е', 'e'], ['ё', 'yo'], ['ж', 'zh'], ['з', 'z'],
							['и', 'i'], ['й', 'y'], ['к', 'k'], ['л', 'l'], ['м', 'm'], ['н', 'n'], ['о', 'o'], ['п', 'p'], ['р', 'r'],
							['с', 's'], ['т', 't'], ['у', 'u'], ['ф', 'f'], ['х', 'h'], ['ц', 'c'], ['ч', 'ch'], ['ш', 'sh'], ['щ', 'shch'], ['ъ', ''], ['ы', 'y'], ['ь', ''], ['э', 'e'], ['ю', 'yu'], ['я', 'ya'],
							['А', 'A'], ['Б', 'B'], ['В', 'V'], ['Г', 'G'], ['Д', 'D'], ['Е', 'E'], ['Ё', 'YO'], ['Ж', 'ZH'], ['З', 'Z'],
							['�?', 'I'], ['Й', 'Y'], ['К', 'K'], ['Л', 'L'], ['М', 'M'], ['Н', 'N'], ['О', 'O'], ['П', 'P'], ['Р', 'R'],
							['С', 'S'], ['Т', 'T'], ['У', 'U'], ['Ф', 'F'], ['Х', 'H'], ['Ц', 'C'], ['Ч', 'CH'], ['Ш', 'SH'], ['Щ', 'SHCH'],
							['Ъ', ''], ['Ы', 'Y'], ['Ь', ''], ['Э', 'E'], ['Ю', 'YU'], ['Я', 'YA'], ['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd'], ['e', 'e'],
							['f', 'f'], ['g', 'g'], ['h', 'h'], ['i', 'i'], ['j', 'j'], ['k', 'k'], ['l', 'l'], ['m', 'm'], ['n', 'n'], ['o', 'o'],
							['p', 'p'], ['q', 'q'], ['r', 'r'], ['s', 's'], ['t', 't'], ['u', 'u'], ['v', 'v'], ['w', 'w'], ['x', 'x'], ['y', 'y'],
							['z', 'z'], ['A', 'A'], ['B', 'B'], ['C', 'C'], ['D', 'D'], ['E', 'E'], ['F', 'F'], ['G', 'G'], ['H', 'H'], ['I', 'I'], ['J', 'J'], ['K', 'K'],
							['L', 'L'], ['M', 'M'], ['N', 'N'], ['O', 'O'], ['P', 'P'], ['Q', 'Q'], ['R', 'R'], ['S', 'S'], ['T', 'T'], ['U', 'U'], ['V', 'V'], ['W', 'W'], ['X', 'X'], ['Y', 'Y'],
							['Z', 'Z'], [' ', '-'], ['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'], ['-', '-']
							);
					var newStr = new String();
					for (var i = 0; i < str.length; i++)
					{
						ch = str.charAt(i);
						var newCh = '';
						for (var j = 0; j < cyr2latChars.length; j++)
							if (ch == cyr2latChars[j][0])
								newCh = cyr2latChars[j][1];
						newStr += newCh;
					}
					newStr = newStr.replace(/[-]{2,}/gim, '-').replace(/\n/gim, '').toLowerCase();
					if (typeof firsturl != 'undefined' && firsturl != '')
					{
						newStr = firsturl + '/' + newStr;
					}
					return newStr;
				},
				sendGoogleStatic: function(category, anchor, label)
				{
					_gaq.push(['_trackEvent', category, anchor, label]);
				}
			}

	/*- fancybox -*/
	$('.fancybox').fancybox({
		fitToView: false,
		helpers: {
			overlay: {
				locked: false
			}
		}
	});

	$("div.sliderkit-nav-clip>ul>li").on("click", function()
	{
		$('div.sliderkit-nav-clip>ul>li').removeClass('sliderkit-selected');
		$(this).addClass('sliderkit-selected');
	});

	jQuery(".masked-phone").mask("+7 (999) 999-99-99");

});
